package com.zxy.leetcode.lcof;

/**
 * https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/
 *
 * 替换空格
 * 请实现一个函数，把字符串 s 中的每个空格替换成"%20"。
 */
public class Test05 {

    public static void main(String[] args) {
        Test05 test = new Test05();
        System.out.println(test.replaceSpace("We are happy."));
    }

    public String replaceSpace(String s) {
        StringBuilder stringBuilder = new StringBuilder(s.length() * 2);

        for (char c : s.toCharArray()) {
            if (c == ' ') {
                stringBuilder.append("%20");
            }else {
                stringBuilder.append(c);
            }
        }

        return stringBuilder.toString();
    }

}
